package com.nervenets.web.controller.handler.user.user;

import com.nervenets.web.controller.handler.Handler;
import com.nervenets.web.controller.handler.user.UserModel;
import com.nervenets.web.entity.MessageCode;
import com.nervenets.web.hibernate.domain.user.User;

import javax.servlet.http.HttpServletRequest;

public class UserWeixinCheckHandler extends Handler<UserWeixinCheckParams> {
    @Override
    public String handle(UserWeixinCheckParams params, HttpServletRequest request) throws Exception {
        User wechatUser = userDao.getUserByWechatId(params.getOpenId());
        if (null == wechatUser) return errorMessage(MessageCode.code_404, "账号不存在");

        UserModel userModel = new UserModel(wechatUser, 1, globalVariablesService.getGlobalRule().getDefaultAvatar());
        return successMessage(userModel);
    }

    @Override
    public String result() throws Exception {
        return successMessage();
    }

}
